package com.hk.huakangcompany.model.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @Author: aerfazhe
 * @Date: 2021/7/26 9:33
 * @Statement: 登录字段
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class LoginAdmin implements UserDetails {

    private Integer id;
    private String name;
    private String email;
    private String password;
    List<GrantedAuthority> authorities;

    @ApiModelProperty("登录日志Id，该字段主要用于记录退出时间条件标识使用")
    private Integer loginLogId;

    public LoginAdmin(Integer id, String name, String email, String password, List<GrantedAuthority> authorities) {
        this.id = id;
        this.name = name;
        this.email = email;
        this.password = password;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getUsername() {
        return email;
    }

    /**
     * 账户是否过期
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 是否禁用
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 密码是否过期
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否启用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
